﻿using System;
using System.Windows;
using CrystalDecisions.CrystalReports.Engine;
using StudentManagement.Reports;

namespace StudentManagement
{
    /// <summary>
    /// Interaction logic for FrmReport.xaml
    /// </summary>
    public partial class FrmReport
    {
        private readonly string _reportName;

        public FrmReport()
        {
            InitializeComponent();
        }

        public FrmReport(string reportName)
        {
            InitializeComponent();
            _reportName = reportName;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DisplayReport(_reportName);
        }

        private void DisplayReport(string reportName)
        {
            try
            {
                ReportClass report = null;
                switch (reportName)
                {
                    case "Student":
                        report = new StudentReport();
                        break;
                    case "Subject":
                        report = new SubjectReport();
                        break;
                    case "SeattingTime": 
                        report = new SeattingTimeReport();
                        break;
                }

                if (report == null) return;
                var filePath = System.Windows.Forms.Application.StartupPath + "\\StudentDB.mdb";
                report.DataSourceConnections[0].SetConnection(string.Empty, filePath, true);
                crystalReportViewer.ReportSource = report;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
